package com.htu.service.Impl;

import com.aliyuncs.CommonRequest;
import com.aliyuncs.CommonResponse;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.http.MethodType;
import com.aliyuncs.profile.DefaultProfile;
import com.htu.service.SmsService;
import org.springframework.stereotype.Service;

@Service
public class SmsServiceImpl implements SmsService {

    @Override
    public String smsCode(String telephone) {
        DefaultProfile profile = DefaultProfile.getProfile("cn-hangzhou","LTAI5tLEXZJRyC41o1Tmz6dp","UC9UJ3Bd4WaENINssomSlSFVlTukRf");
        DefaultAcsClient client = new DefaultAcsClient(profile);
        CommonRequest request = new CommonRequest();
        request.setMethod(MethodType.POST);
        request.setDomain("dysmsapi.aliyuncs.com");
        request.setVersion("2017-05-25");
        request.setAction("SendSms");
        int number =(int)(Math.random()*10000);
        System.out.println(number);
        request.putQueryParameter("PhoneNumbers",telephone);
        request.putQueryParameter("SignName","阿里云短信测试");
        request.putQueryParameter("TemplateCode","SMS_154950909");
        request.putQueryParameter("TemplateParam","{\"code\":\""+number+"\"}");

        try {
            CommonResponse response =client.getCommonResponse(request);
            System.out.println(response.getData());

        } catch (ClientException e) {
            e.printStackTrace();
        }
        return number+"";
    }
}
